package com.demo.petshop.controller;

import com.demo.petshop.entity.Stores;
import com.demo.petshop.entity.StoresInfo;
import com.demo.petshop.service.ProductsService;
import com.demo.petshop.service.StoreServicesService;
import com.demo.petshop.service.StoreTagsService;
import com.demo.petshop.service.StoresService;
import com.demo.petshop.util.Result;
import jakarta.websocket.OnClose;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *  控制层。
 *
 * @author lenovo
 * @since 2025-06-11
 */
@RestController
@RequestMapping("/stores")
public class StoresController {

    @Autowired
    private StoresService storesService;

    @Autowired
    private StoreTagsService storeTagsService;

    @Autowired
    private ProductsService productsService;

    @Autowired
    private StoreServicesService storeServicesService;


    @GetMapping("/nearby")
    public Object getNearbyStores(@RequestParam String latitude,
                                  @RequestParam String longitude,
                                  @RequestParam String radius,
                                  @RequestParam String tagId){
        return storesService.getNearbyStores(latitude, longitude, radius, tagId);
    }

    @GetMapping("/list")
    public Object getStoresList(@RequestParam Integer tagId){
        return storesService.getAll(tagId);
    }

    @GetMapping("tags")
    public Object getStoresTags(){
        return Result.success(storeTagsService.list());
    }

    @GetMapping("/getById")
    public Object getByTagId(@RequestParam Integer id){
        return storesService.getByTagId(id);
    }

    @GetMapping("/store")
    public Object getStore(@RequestParam Integer id){
            return storesService.getStore(id);
    }

    @GetMapping("/storesNoId")
    public Object getStoreNoId(){
        return storesService.getStoresNoId();
    }



    @GetMapping("/products")
    public Object getProducts(@RequestParam Integer storeId){
        return productsService.getProducts(storeId);
    }

    @GetMapping("/search")
    public Object search(String keyword,int storeId){
        return productsService.searchOfStoreId(keyword,storeId);
    }

    @GetMapping("/category")
    public Object category(int categoryId,int storeId){
        return productsService.categoryOfStoreId(categoryId,storeId);
    }

    @GetMapping("/orderBySales")
    public Object orderBySale(int categoryId,int storeId){
        return productsService.orderBySaleOfStoreId(categoryId,storeId);
    }

    @GetMapping("/orderByPrice")
    public Object orderByPrice(int categoryId,int storeId){
        return productsService.orderByPriceOfStoreId(categoryId,storeId);
    }

    @GetMapping("/reOrderByPrice")
    public Object reOrderByPrice(int categoryId,int storeId){
        return productsService.reOrderByPriceOfStoreId(categoryId,storeId);
    }

    @GetMapping("/services")
    public Object getServices(@RequestParam Integer storeId){
        return storeServicesService.getServices(storeId);
    }

    @GetMapping("/reviews")
    public Object getReviews(@RequestParam Integer storeId){
        return storesService.getReviews(storeId);
    }

    @GetMapping("/reRating")
    public Object reRating(){
        return storesService.reRating();
    }

    @GetMapping("/stats")
    public Object stats(){
        return storesService.stats();
    }

    @PostMapping("/update")
    public Object update(@RequestBody StoresInfo storesInfo){
        return storesService.updateStore(storesInfo);
    }

    @PostMapping("/addStore")
    public Object addStore(@RequestBody StoresInfo storesInfo){
        return storesService.addStore(storesInfo);
    }

    @GetMapping("/delStore")
    public Object delStore(int storeId){
        return storesService.delStore(storeId);
    }

    @GetMapping("/getStoreList")
    public Object getStoreList(){
        return storesService.getStoreList();
    }
    @GetMapping("/shopkeeper-stats")
    public Result getShopkeeperStats(){
        return Result.success(storesService.getShopkeeperStats());
    }

}
